package com.andy.common.base

import android.content.Intent
import android.content.pm.ActivityInfo
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX

/**
 * Author:Andy
 * Date:2023/3/20 14:28
 * Description:BaseActivity
 */
abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
    protected open var mBinding: VB? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = getViewBinding()
        setContentView(mBinding?.root)
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
        initStatusBar()
        initNavigationBar()
    }


    open fun initStatusBar() {
        UltimateBarX.statusBar(this)
            .fitWindow(true)
            .colorRes(com.andy.base.R.color.color_317CFF)
            .light(false)
            .apply()
    }

    open fun initNavigationBar() {
        UltimateBarX.navigationBar(this)
            .fitWindow(true)
            .colorRes(com.andy.base.R.color.white)
            .light(false)
            .apply()
    }

    abstract fun getViewBinding(): VB

    protected fun startActivity(z: Class<*>) {
        startActivity(Intent(applicationContext, z))
    }

    override fun onDestroy() {
        super.onDestroy()
        mBinding = null
    }
}